//#include <zebra.h>
#include "command.h"
#include "vtysh.h"
#include "if.h"

DEFUN(mac_aging_time_config,
      mac_aging_time_config_cmd,
      "mac address-table aging-time <0-1000000>",
      "MAC Address table configuration"
      "Set MAC Address tablee aging-time"
      "Default: 300 seconds; 0: Disable MAC Address aging")
{
    char cmdstr[128];
    snprintf(cmdstr, 128, "sudo config mac-address-table aging-time %s",argv[0]);
    execute_linux_cmd_pipe(cmdstr);
    return CMD_SUCCESS;
}

DEFUN(no_mac_aging_time_config,
      no_mac_aging_time_config_cmd,
      "no mac address-table aging-time",
      NO_STR
      "MAC Address table configuration"
      "Reset MAC Address table aging-time to default")
{
    char cmdstr[128];
    snprintf(cmdstr, 128, "sudo config mac-address-table aging-time --default");
    execute_linux_cmd_pipe(cmdstr);
    return CMD_SUCCESS;
}

DEFUN (show_mac_aging_time, show_mac_aging_time_cmd,
       "show mac address-table aging-time",
       SHOW_STR
       "Show global MAC Address aging time\n")
{
    execute_linux_cmd_pipe("show mac-address-table aging-time");
    return CMD_SUCCESS;
}

DEFUN(mac_address_table_config,
    mac_address_table_config_cmd,
    "mac address-table static MAC vlan VLAN interface PORT",
    "MAC Address table configuration\n"
    "MAC Address table configuration\n"
    "Add static MAC address entry\n"
    "MAC address, in xx:xx:xx:xx:xx:xx format\n"
    "Specify the VLAN ID\n"
    "VLAN ID, in Vlan+NUM format\n"
    "Specify the interface name\n"
    "Interface name\n")
{
  char cmdstr[128];
  snprintf(cmdstr, 128, 
    "sudo config mac-address-table set --type static --mac %s --vlan %s --port %s"
    ,argv[0], argv[1], argv[2]);
  execute_linux_cmd_pipe(cmdstr);
  return CMD_SUCCESS;
}

DEFUN(no_mac_address_table_config,
    no_mac_address_table_config_cmd,
    "no mac address-table static MAC vlan VLAN interface PORT",
    NO_STR
    "MAC Address table configuration\n"
    "MAC Address table configuration\n"
    "Remove static MAC address entry\n"
    "MAC address, in xx:xx:xx:xx:xx:xx format\n"
    "Specify the VLAN ID\n"
    "VLAN ID, in Vlan+NUM format\n"
    "Specify the interface name\n"
    "Interface name\n")
{
  char cmdstr[128];
  snprintf(cmdstr, 128, 
    "sudo config mac-address-table erase --type static --mac %s --vlan %s --port %s"
    ,argv[0], argv[1], argv[2]);
  execute_linux_cmd_pipe(cmdstr);
  return CMD_SUCCESS;
}

DEFUN (show_mac_address_table, show_mac_address_table_cmd,
  "show mac address-table static",
  SHOW_STR
  "Show global MAC Address table\n"
  "Show global MAC Address table\n"
  "Show static MAC Address table entries\n")
{
  char cmdstr[128];
  snprintf(cmdstr, 128, "show mac-address-table static-items");
  execute_linux_cmd_pipe(cmdstr);
  return CMD_SUCCESS;
}

void
vtysh_l2_init (void)
{
    install_element (CONFIG_NODE, &mac_aging_time_config_cmd);
    install_element (CONFIG_NODE, &no_mac_aging_time_config_cmd);
    install_element (ENABLE_NODE, &show_mac_aging_time_cmd);
    install_element (VIEW_NODE, &show_mac_aging_time_cmd);
    install_element (CONFIG_NODE, &mac_address_table_config_cmd);
    install_element (CONFIG_NODE, &no_mac_address_table_config_cmd);
    install_element (VIEW_NODE, &show_mac_address_table_cmd);
    install_element (ENABLE_NODE, &show_mac_address_table_cmd);
}
